<template>
  <div v-if="$store.state.edit.row && $store.state.main.entry.sources">
    <input type="hidden" :value="init()" />
    <div
      class="form-group mt15"
      v-for="(value, f1) in $store.state.edit.row.fields"
      :key="f1"
    >
      <el-form-item :label="m(value)" label-width="120px">
        <el-select
          size="mini"
          v-model="ruleValues[f1]"
          filterable
          clearable
          :multiple="true"
        >
          <el-option
            v-for="k in Object.keys(
              $store.state.edit.entry.sources['roleSource']
            )"
            :key="k"
            :label="m($store.state.edit.entry.sources['roleSource'][k])"
            :value="k"
          >
          </el-option>
        </el-select>
      </el-form-item>
    </div>
  </div>
</template>

<script>
import { m } from "@/store/yg/common/local";

export default {
  data() {
    return {
      loaded: false,
      ruleValues: {}
    };
  },
  props: ["field"],
  methods: {
    init() {
      if (this.loaded) {
        return "";
      }
      if (this.$store.state.edit.row["permissionJson"]) {
        this.ruleValues = JSON.parse(
          this.$store.state.edit.row["permissionJson"]
        );
      }
      for (var k in this.$store.state.edit.row.fields) {
        if (!this.ruleValues[k]) {
          this.ruleValues[k] = [];
        }
      }
      this.loaded = true;
      return "";
    },
    m(k) {
      return m(k);
    },
    callbefore() {
      this.$store.state.edit.row["permissionJson"] = JSON.stringify(
        this.ruleValues
      );
    }
  },
  created() {}
};
</script>
